﻿@using BusinessObjects
@using WebUI.HtmlHelpers
@model WebUI.Models.NccListViewModel


<div id="loading">
    <img src="~/Content/images/preloader-01.gif" />
</div>
<div class="current-sort" sort-data="@Model.CurrentSort" sort-type="@Model.SortType" style="display: none">@Model.CurrentSort</div>
<table class="ncc-article common-table" border="0" cellspacing="0" cellpadding="0">
    <thead>
        <tr>
            <th>STT</th>
            <th>@Ncc.Const.MA</th>
            <th class="sort-column" sort-data="HoTen" is-active="true" sort-type="asc">
                <div>@Ncc.Const.HO_TEN <span /></div>
            </th>
            <th class="sort-column" sort-data="NamSinh">
                <div>@Ncc.Const.NAM_SINH<span /></div>
            </th>
            <th>
                <div>@Ncc.Const.NOI_CAP_TRUY_LINH<span /></div>
            </th>
            <th>
                <div>@Ncc.Const.NGUYEN_QUAN<span /></div>
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach (var ncc in Model.Nccs)
        {
            <tr>
                <td style="width: 30px;"></td>
                <td class="td-center" style="width: 70px;" align="center">@ncc.Ma</td>
                <td style="width: 300px;">@ncc.HoTen</td>
                <td class="td-center" style="width: 100px;">@ncc.NamSinh</td>
                <td style="width: 250px;">@ncc.NoiCapTruyLinh</td>
                <td style="width: 250px;">@ncc.NguyenQuan</td>
            </tr>
        }
    </tbody>
</table>
<div class="ncc-pager">
    @Html.PageAjaxLinks(Model.PagingInfo, new AjaxOptions
                                        {
                                            UpdateTargetId = "ncclist",
                                            LoadingElementId = "loading"
                                        },
                        i => Url.Action("ListData", new { sort = Model.CurrentSort, sortType = Model.SortType, pageIndex = i }))
</div>

@*<script>
    //function HandleJquery() {
        $(document).ready(function () {
            $(".sort-column span").removeAttr("class");

            var currentSort = $(".current-sort").attr("sort-data");
            var currentSortType = $(".current-sort").attr("sort-type");

            //Apply css for sorted column
            if (currentSortType == "asc")
                $(".sort-column[sort-data=" + currentSort + "] span").attr("class", "order-icon-asc");
            else
                $(".sort-column[sort-data=" + currentSort + "] span").attr("class", "order-icon-desc");

            $(".sort-column").click(function () {
                var sortType = "asc";
                var sort;

                //Check is current sorted
                var abc = $(this).attr("is-active");

                //Original column
                if (abc == "true") {
                    //Reverse sort type
                    if ($(this).attr("sort-type") == "asc")
                        sortType = "desc";
                    else
                        sortType = "asc";
                }

                sort = $(this).attr("sort-data");

                var url = "/Ncc/ListData?sort=" + sort + "&sortType=" + sortType;

                //Display loading
                $("#loading").css("display", "block");

                $.get(url, function (data) {
                    //Load data
                    $("#ncclist").html(data);

                    $(".sort-column").removeAttr("sort-type");
                    $(".sort-column").removeAttr("is-active");
                    $(".sort-column span").removeAttr("class");
                    $(".sort-column[sort-data=" + sort + "]").attr("is-active", true);
                    $(".sort-column[sort-data=" + sort + "]").attr("sort-type", sortType);

                    //Hide loading
                    $("#loading").css("display", "none");

                    //Re-bind jquery handle
                    //HandleJquery();

                });
            });
            
            $(".ncc-pager a").click(function () {
                alert("ckl");
                var b = {
                    "sort": "@Model.CurrentSort",
                    "sortType": "@Model.SortType",
                    "pageIndex": $(this).text(),
                    "nccSearchModel": {
                        "HoTen": "@Model.NccSearchModel.HoTen",
                        "NamSinh": "@Model.NccSearchModel.NamSinh"
                    }
                };

                var e = JSON.stringify(b);

                $.get({
                    url: '@Url.Action("ListData")',
                    type: 'POST',
                    contentType: 'application/json; charset=utf-8',
                    data: e,
                    dataType: 'json',
                    cache: false,
                    success: function (data) {
                        alert("ckl");
                        $("#ncclist").html(data);

                        //Re-bind jquery handle
                        //HandleJquery();
                    },
                    error: function(ex) {
                        alert(ex);
                    }
                });
            });
        });
    //}

    //HandleJquery();
</script>*@
